package com.knowif.dto;

import com.knowif.pojo.*;
import org.springframework.beans.BeanUtils;

import javax.validation.constraints.NotEmpty;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/**
 * @author ：Xh
 * @date ：Created in 2019/6/22 0022 22:40
 */
public class TutorInfoDto {

    /**
     * 咨询价格:最低价格
     */
    @NotEmpty(message = "咨询价格不能为空")
    private Double consultPrice;

    /**
     * 用户自述
     */
    private String descrition_NotFileter;

    /**
     * 优惠价格
     */
    private Double preferentialPrice;

    /**
     * 所在地
     */
    private String location;

    /**
     * 擅长话题
     */
    List<Topic> topic;

    /**
     * 标签
     */
    List<Label> label;

    /**
     * 是否开启快问
     */
    private Integer isFastAsk;

    /**
     * 快问价格
     */
    private BigDecimal fastAskPrice;

    /**
     * 姓名
     */
    private String fullName;
    /**
     * 用户名称
     */
    private String username;
    /**
     * 自我介绍
     */
    private String selfShow;
    /**
     * 微信openid
     */
    @NotEmpty(message = "openid不能空")
    private String openid;
    /**
     * 用户头像
     */
    private String avatarUrl;
    /**
     * 电话号码
     */
    private String phoneNum;

    /**
     * 旧的接口在用，
     */
    private List<UserItem> userItems;
    
    /**
     * 新的接口数据，需要转化为旧的接口在用
     */
    private List<CategoryDto> categorys;

    /**
     * 是否推荐 0默认1为推荐
     */
    private Integer isTj;
    /**
     * 推荐页展示排序号
     */
    private Integer tjOrdNum;
    /**
     * 是否展示在发现页
     */
    private Integer isFx;

    /**
     * 发现页展示排序
     */
    private Integer fxOrdNum;
    /**
     * 闪光点
     */
    private String flashPoint;

    private TUser tUser;

    public String getSelfShow() {
        return selfShow;
    }

    public void setSelfShow(String selfShow) {
        this.selfShow = selfShow;
    }

    public Double getConsultPrice() {
        return consultPrice;
    }

    public void setConsultPrice(Double consultPrice) {
        this.consultPrice = consultPrice;
    }

    public String getDescrition_NotFileter() {
		return descrition_NotFileter;
	}

	public void setDescrition_NotFileter(String descrition_NotFileter) {
		this.descrition_NotFileter = descrition_NotFileter;
	}

	public Double getPreferentialPrice() {
        return preferentialPrice;
    }

    public void setPreferentialPrice(Double preferentialPrice) {
        this.preferentialPrice = preferentialPrice;
    }

    public String getLocation() {
        return location;
    }

    public void setLocation(String location) {
        this.location = location;
    }

    public List<Topic> getTopic() {
        return topic;
    }

    public void setTopic(List<Topic> topic) {
        this.topic = topic;
    }

    public List<Label> getLabel() {
        return label;
    }

    public void setLabel(List<Label> label) {
        this.label = label;
    }

    public String getFullName() {
        return fullName;
    }

    public void setFullName(String fullName) {
        this.fullName = fullName;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getOpenid() {
        return openid;
    }

    public void setOpenid(String openid) {
        this.openid = openid;
    }

    public String getAvatarUrl() {
        return avatarUrl;
    }

    public void setAvatarUrl(String avatarUrl) {
        this.avatarUrl = avatarUrl;
    }

    public String getPhoneNum() {
        return phoneNum;
    }

    public void setPhoneNum(String phoneNum) {
        this.phoneNum = phoneNum;
    }

    public Integer getTjOrdNum() {
        return tjOrdNum;
    }

    public void setTjOrdNum(Integer tjOrdNum) {
        this.tjOrdNum = tjOrdNum;
    }

    public Integer getIsFx() {
        return isFx;
    }

    public void setIsFx(Integer isFx) {
        this.isFx = isFx;
    }

    public Integer getFxOrdNum() {
        return fxOrdNum;
    }

    public void setFxOrdNum(Integer fxOrdNum) {
        this.fxOrdNum = fxOrdNum;
    }

    public TUser gettUser() {
        return tUser;
    }

    public void settUser(TUser tUser) {
        this.tUser = tUser;
    }

    public List<UserItem> getUserItems() {
    	if((userItems == null || userItems.isEmpty()) && categorys != null  && !categorys.isEmpty()){
    		userItems = CategoryDto.change2UserItems(this.categorys);
    	}
        return userItems;
    }

    public void setUserItems(List<UserItem> userItems) {
        this.userItems = userItems;
    }

    public Integer getIsTj() {
        return isTj;
    }

    public void setIsTj(Integer isTj) {
        this.isTj = isTj;
    }

    public String getFlashPoint() {
        return flashPoint;
    }

    public void setFlashPoint(String flashPoint) {
        this.flashPoint = flashPoint;
    }

    public Integer getIsFastAsk() {
        return isFastAsk;
    }

    public void setIsFastAsk(Integer isFastAsk) {
        this.isFastAsk = isFastAsk;
    }

    public BigDecimal getFastAskPrice() {
        return fastAskPrice;
    }

    public void setFastAskPrice(BigDecimal fastAskPrice) {
        this.fastAskPrice = fastAskPrice;
    }

    public List<CategoryDto> getCategorys() {
		if(userItems != null && !userItems.isEmpty() && (categorys == null  || categorys.isEmpty())){
			categorys = CategoryDto.userItems2CategoryDto(this.userItems);
    	}
		return categorys;
	}

	public void setCategorys(List<CategoryDto> categorys) {
		this.categorys = categorys;
	}
	
	
	public static List<TutorInfoDto> tutorInfo2TutorInfoDto(List<TutorInfo> tutorInfos){
		if(tutorInfos == null || tutorInfos.isEmpty()){
			return new ArrayList<>();
		}
		List<TutorInfoDto> tutorInfoDtos = new ArrayList<TutorInfoDto>();
		List<CategoryDto> categoryDtos = null;
		TutorInfoDto tutorInfoDto = null;
		CategoryDto categoryDto = null;
		for(TutorInfo tutorInfo : tutorInfos){
			tutorInfoDto = new TutorInfoDto();
			BeanUtils.copyProperties(tutorInfo, tutorInfoDto);
			tutorInfoDto.setTopic(tutorInfo.getTopic());
			tutorInfoDto.setLabel(tutorInfo.getLabel());
			tutorInfoDto.settUser(tutorInfo.gettUser());
			categoryDtos = new ArrayList<>();
			List<UserItem> userItems = tutorInfo.getUserItem();
			if(userItems != null && !userItems.isEmpty()){
				for(UserItem userItem : userItems){
					categoryDto = new CategoryDto();
					System.out.println(userItem);
					BeanUtils.copyProperties(userItem, categoryDto);

					if(userItem.getTutorEducationInfo() != null){
						BeanUtils.copyProperties(userItem.getTutorEducationInfo(),categoryDto);
					}
					categoryDto.setId(userItem.getId());
					categoryDtos.add(categoryDto);
				}
			}
			tutorInfoDto.setCategorys(categoryDtos);
			tutorInfoDtos.add(tutorInfoDto);
		}
		return tutorInfoDtos;
	}

	@Override
	public String toString() {
		return "TutorInfoDto [consultPrice=" + consultPrice + ", descrition_NotFileter=" + descrition_NotFileter
				+ ", preferentialPrice=" + preferentialPrice + ", location=" + location + ", topic=" + topic
				+ ", label=" + label + ", fullName=" + fullName + ", username=" + username + ", openid=" + openid
				+ ", avatarUrl=" + avatarUrl + ", phoneNum=" + phoneNum + ", userItems=" + userItems + ", categorys="
				+ categorys + ", isTj=" + isTj + ", flashPoint=" + flashPoint + ", tUser=" + tUser + "]";
	}


}
